﻿@{
   // ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

<div class="SearchBox layui-form">
    搜索ID：
    <div class="layui-inline">
        <input class="layui-input" name="title" id="title" autocomplete="off">
    </div>
    状态：<div class="layui-inline">
           <select name="status" id="status" lay-verify="required">
               <option value="-1">请选择</option>
               <option value="0">显示</option>
               <option value="1">隐藏</option>
           </select>

    </div>
    <button class="layui-btn" data-type="reload">搜索</button>
</div>
<div style="margin:10px 0px;">
    
        <button class="layui-btn layui-btn-normal" onclick="add()"><i class="layui-icon">&#xe61f;</i> 添加</button>
     
</div>
    <table class="layui-hide" id="LAY_table_user" lay-filter="user"></table>
    <script>
        layui.use(['table', 'laytpl', 'layer'], function () {
            var table = layui.table;
            var laytpl = layui.laytpl;
            var layer = layui.layer;
            //方法级渲染
            table.render({
                elem: '#LAY_table_user'
              , url: '/admin/SysLinksMgr/GetSysLinksList'
              , cols: [[
                { checkbox: true, fixed: true }
                , { field: 'id', title: 'ID', width: 80, fixed: true }
                , { field: 'title', title: '名称', width: 180 }
                , { field: 'image', title: '图标', width: 100 }
                , { field: 'status', title: '状态', width: 100, templet: '#status_tpl' }
                , { field: 'url', title: '地址', width: 150 }
                , { field: 'clicks', title: '点击数', width: 80 }
                , { field: 'set', title: '操作', align: 'center', width: 200, toolbar: '#set_tool' }
              ]]
                , id: 'tid'
                //,skin: 'line' //风格
                , even: false
                , limits: [15, 30, 50]
                , limit: 15
                , loading: true
                , page: true
                , requert: {
                    pageName: 'PageIndex' //页码的参数名称，默认：page
                    , limitName: 'PageSize' //每页数据量的参数名，默认：limit
                }
                , height: 'full-240'
            });

            var $ = layui.$, active = {
                reload: function () {
                    table.reload('tid', {
                        where: {
                            title: $('#title').val(),
                            status: $('#status').val()
                        }
                    });
                }
            };

            $('.SearchBox .layui-btn').on('click', function () {
                var type = $(this).data('type');
                active[type] ? active[type].call(this) : '';
            });


        });

        function deleteRole(rid) {
            deleteById("/admin/SysLinksMgr/Delete", { id: rid });
        }

        function add() {
            layer.open({
                type: 2,
                title: '添加链接',
                maxmin: true,
                shadeClose: true, //点击遮罩关闭层
                area: ['680px', '400px'],
                content: 'AddOrUp'
            });

        }
        function update(id) {
            layer.open({
                type: 2,
                title: '修改链接',
                maxmin: true,
                shadeClose: true, //点击遮罩关闭层
                area: ['680px', '400px'],
                content: 'AddOrUp?id=' + id
            });
        }
    </script>

    <script type="text/html" id="status_tpl">

        {{#  if(d.status < 1){ }}
        <span class="layui-badge-rim layui-bg-green">显示</span>
        {{#  } else { }}
        <span class="layui-badge-rim layui-bg-gray">隐藏</span>
        {{#  } }}
    </script>
    <script type="text/html" id="set_tool">
        <button class="layui-btn layui-btn-mini layui-btn-normal" onclick="update('{{ d.id }}')">
            <i class="layui-icon">&#xe642;</i>修改
        </button>
        <button class="layui-btn layui-btn-mini layui-btn-danger" onclick="deleteRole('{{ d.id}}')">
            <i class="layui-icon">&#xe640;</i>删除
        </button>
    </script>
